// pages/notice/cepingreport/cepingreport.js
let wxCharts = require('../../../utils/wxcharts.js');
const app = getApp();
let tool = require('../../../utils/tool.js');
let windowW = 0;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imageurl: 'https://yxpmaterial.oss-cn-beijing.aliyuncs.com/',
        bardata: [],
        student: {},
        advise: {},
        result: {},
        pageName: '测评报告',
        navH: app.globalData.navHeight,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        //图标处理
        // 屏幕宽度

        this.data.id = options.id;
        this.getdata();
        this.setData({
            imageWidth: wx.getSystemInfoSync().windowWidth
        });
        //计算屏幕宽度比列
        windowW = this.data.imageWidth / 375;

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {


    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    getdata: function() {

        let that = this;
        //获取主页折线图的数据
        let paramArr = {
            access_token: app.globalData.studentInfo.access_token,
            id: this.data.id
        }
        let rs = tool.getSign(paramArr, app.globalData.key); //返回 bodyParam heaer sign
        let sign = rs.sign;
        let apiUrl = app.globalData.apiURL + "message/examreport?sign=" + sign;
        let reportPro = new Promise(
            function(resolve, reject) {
                wx.request({
                    url: apiUrl,
                    header: rs.header,
                    data: rs.bodyParam,
                    method: 'post',
                    success(res) {
                        resolve(res);
                    }
                })
            }

        );
        reportPro.then(function(rs) {
            if (rs.data.code == 1) {
                that.setData({
                    student: rs.data.data.student,
                    advise: rs.data.data.advises,
                    result: rs.data.data.result,
                    bardata: [{
                            name: "section",
                            data: [rs.data.data.advises.section],
                            color: "#0091EC"
                        },
                        {
                            name: "score",
                            data: [rs.data.data.result.score],
                            color: '#27AE60'
                        },
                    ]

                })
                let options = {
                    data: that.data.bardata,
                    xLabel: ' ',
                    style: 'bar',
                    showTooltip: true,
                    tooltip: '{a}：{b}',
                    showLabel: false,
                    rectStyle: 'normal',
                    canvasHeight: 100
                }
                that.lineChart = that.selectComponent('#bar');
                that.lineChart.setOptions(options);
                that.lineChart.initChart(250 * windowW, 133);
            } else if (rs.data.code == 10001) {
                wx.redirectTo({
                    url: '/pages/login/login',
                })
            }

        });
    }
})